﻿using B.S.BaseData.Domain.Entities;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interfaces;
using B.S.BaseData.Read.API.Command.MenuCommand;
using B.S.BaseData.Read.API.Command.RoleCommand;
using MediatR;

namespace B.S.BaseData.Read.API.CommandHandler.RoleHandler
{
    public class GetRoleTreeHandler : IRequestHandler<GetRoleTreeCommand, APIResult<List<Role>>>
    {
        private readonly IBaseRepository<Role> _baseRepository;

        public GetRoleTreeHandler(IBaseRepository<Role> baseRepository)
        {
            _baseRepository = baseRepository;
        }

        public async Task<APIResult<List<Role>>> Handle(GetRoleTreeCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Role>> result = new APIResult<List<Role>>();
            result.Code = APIEnum.Success;
            result.Msg = "获取成功";
            var entity = _baseRepository.GetAll().ToList();
            result.Data = entity;

            return await Task.FromResult(result);
        }
    }
}
